package com.ctsi.commons.util.id;


/**
 * 产生随机数字，运行时刻不修改属性就线程安全 
 * @author yueming
 *
 */
public class NumStrGenerator {
	private RandomNum randN;

	private RandomStrg randS;

	public NumStrGenerator() {
		randS = new RandomStrg();	
		randS.setCharset("A-Z");
		randS.setAlgorithm("SHA1PRNG");
		randS.getRandom();

		
		randN = new RandomNum();
		randN.setRange(10, 100000l);
		randN.setAlgorithm("SHA1PRNG");
		randN.getRandom();
	}
	public NumStrGenerator(int len) {
		this();
		if (len > 1)
		randS.setLength(len);		

	}
	public void setLength(int len) {
		if (len < 1)
			return;
		randS.setLength(len);
	}
	public void setHmap(boolean check) {

		randS.setHset(check);
	}
	private static String nowDateString() {
		//SimpleDateFormat df = new SimpleDateFormat("ddHHmmss");
		//return df.format(new Date());
		
		long ee=System.currentTimeMillis();
		String tem=Long.toString(ee);
		return tem.substring(tem.length()-6);		
	}

	public String getShotSeqId() {
		return  randS.getRandom()+nowDateString();
	}

	public String getNextSeqId() {

		return  randS.getRandom()+String.valueOf(System.currentTimeMillis()) ;
	}

	/**
	 * 返回数字,不能在群集环境下作为主键，可以用在数据量比较小的表中作为主键
	 * 
	 * @return
	 */
	public String getNextNumSeqId() {

		return String.valueOf(System.currentTimeMillis()) + randN.getRandom().toString();
	}
}
